package com.work.dyduser.view;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.work.dyduser.R;


/**
 * Created by cyf on 2018/1/25.
 */

public class SignDialog extends Dialog {

    public SignDialog(Context context) {
        super(context, R.style.custom_dialog);
    }


    public static class Builder {
        private Context context;
        private String title;
        private String content;
        private String left;
        private String right;
        private View.OnClickListener leftOCL;
        private View.OnClickListener rightOCL;

        private TextView tv_title;
        private TextView tv_content;
        private TextView leftButton;
        private TextView rightButton;

        public Builder(Context context) {
            this.context = context;
        }

        public Builder setTitleText(String title) {
            this.title = title;
            return this;
        }

        public Builder setContentText(String content) {
            this.content = content;
            return this;
        }



        public Builder setLeftText(String left) {
            this.left = left;
            return this;
        }

        public Builder setRightText(String right) {
            this.right = right;
            return this;
        }

        public Builder setLeftOnClick(View.OnClickListener left) {
            this.leftOCL = left;
            return this;
        }

        public Builder setRightOnClick(View.OnClickListener right) {
            this.rightOCL = right;
            return this;
        }


        public SignDialog create() {

            final SignDialog airDialog = new SignDialog(context);

            View view = LayoutInflater.from(context).inflate(R.layout.sign_dialog, null);
            tv_title = (TextView) view.findViewById(R.id.tv_title);
            tv_content = (TextView) view.findViewById(R.id.tv_content);

            leftButton = (TextView) view.findViewById(R.id.tv_left);
            rightButton = (TextView) view.findViewById(R.id.tv_right);

            if (!TextUtils.isEmpty(title))
                tv_title.setText(title);
            if (!TextUtils.isEmpty(content))
                tv_content.setText(content);


            if (!TextUtils.isEmpty(left))
                leftButton.setText(left);
            if (!TextUtils.isEmpty(right))
                rightButton.setText(right);
            if (leftOCL != null)
                leftButton.setOnClickListener(leftOCL);
            if (rightOCL != null)
                rightButton.setOnClickListener(rightOCL);


            Window win = airDialog.getWindow();
            win.getDecorView().setPadding(0, 0, 0, 0);
            WindowManager.LayoutParams lp = win.getAttributes();
//            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
//            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
            win.setAttributes(lp);
            // win.setGravity(Gravity.NO_GRAVITY);
//            win.setGravity(Gravity.CENTER);
            win.getAttributes().gravity = Gravity.CENTER;
            airDialog.setContentView(view);
            airDialog.setCanceledOnTouchOutside(true);
            // airDialog.setCancelable(false);

            return airDialog;

        }
    }
}
